using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameFrameworkLibraly.BaseObjects
{
    public class AnimatedTexture2D
    {
        private int _frameWidth;

        public Texture2D SpriteTexture { get; set; }
        public int FrameCount { get; set; }
        public int TimeForFrame { get; set; }

        public AnimatedTexture2D(Texture2D spriteTexture, int frameCount, int timeForFrame)
        {
            SpriteTexture = spriteTexture;
            FrameCount = frameCount;
            TimeForFrame = timeForFrame;

            _frameWidth = spriteTexture.Width / frameCount;
        }

        public Rectangle GetSourceRectangle(int frame)
        {
            if(frame>=FrameCount)
                throw new ArgumentException("Frame is out of texture");
            return new Rectangle(frame * _frameWidth, 0, _frameWidth, SpriteTexture.Height);
        }


    }
}
